import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout'

Vue.use(VueRouter)

const routes = [
    {
        path: '*',
        component: (resolve) => require(['@/views/error/404'], resolve),
        hidden: true,
        meta: {
            title: "404-资源不存在 | 芬享",
            auth: "none"//无需任何权限,角色即可访问
        }
    },
    {
        path: '/404',
        component: (resolve) => require(['@/views/error/404'], resolve),
        hidden: true,
        meta: {
            title: "404-资源不存在 | 芬享",
            auth: "none"//无需任何权限,角色即可访问
        }
    },
    {
        path: '/401',
        component: (resolve) => require(['@/views/error/401'], resolve),
        hidden: true,
        meta: {
            title: "401-您没有权限查看 | 芬享",
            auth: "none"//无需任何权限,角色即可访问
        }
    },
    {
        path: '/register',
        name: 'Register',
        component: (resolve) => require(['@/views/register'], resolve),
        meta: {
            title: "注册 | 芬享",
            auth: "none"//无需任何权限,角色即可访问
        }
    },
    {
        path: '/',
        component: Layout,
        children: [
            {
                path: '',
                component: (resolve) => require(['@/views/home'], resolve),
                name: 'HOME',
                meta: {
                    title: "芬享网-美食_菜谱_店铺_吃喝玩乐都可分享",
                    auth: "none"//无需任何权限,角色即可访问
                }
            },
            {
                path: 'changecity',
                component: (resolve) => require(['@/views/city'], resolve),
                name: 'ChangeCity',
                meta: {
                    title: "芬享网-美食_菜谱_店铺_吃喝玩乐都可分享",
                    auth: "none"//无需任何权限,角色即可访问
                }
            },
            {
                path: 'diner/:id',
                component: (resolve) => require(['@/views/diner'], resolve),
                name: 'Diner',
                meta: {
                    title: "的主页",
                    auth: "none"//无需任何权限,角色即可访问
                }
            },
            {
                path: 'moment/:id',
                component: (resolve) => require(['@/views/moment'], resolve),
                name: 'Moment',
                meta: {
                    title: "",
                    auth: "none"//无需任何权限,角色即可访问
                }
            },
            {
                path: 'menu/:id',
                component: (resolve) => require(['@/views/menu'], resolve),
                name: 'Menu',
                meta: {
                    title: "",
                    auth: "none"//无需任何权限,角色即可访问
                }
            },
        ]
    },
    {
        path: '/login',
        name: 'Login',
        component: (resolve) => require(['@/views/login'], resolve),
        meta: {
            title: "登录 | 芬享",
            auth: "none"//无需任何权限,角色即可访问
        }
    },
    {
        path: '/make/moment',
        component: (resolve) => require(['@/views/makemoment'], resolve),
        name: 'MakeMoment',
        meta: {
            title: "写探店 | 芬享",
            auth: "diner",
            roles: ["diner"]
        }
    },
    {
        path: '/make/menu',
        component: (resolve) => require(['@/views/makemenu'], resolve),
        name: 'MakeMenu',
        meta: {
            title: "制菜谱 | 芬享",
            auth: "none",
        }
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}


export default router
